/*
* 管理员所做的事情只有审核房屋和房主信息，对于非法信息标注审核不通过，对于正常信息标注审核通过
 */

package com.example.Gethome.controller;

import com.example.Gethome.repository.HomeRepository;
import com.example.Gethome.service.AdminService;
import com.example.Gethome.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "Administrator")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private HomeService homeService;


    // 管理员通过账号密码进行登录
    @RequestMapping(path = "login")
    public String login(@RequestParam String username, @RequestParam String password) {
        // 如果管理员凭借用户名和密码成功登录，那么就返回登录成功页面，否则返回登陆失败页面，这个需要pc端实现
        if(adminService.loginAdministrator(username, password)) {
            return "success";
        } else return "fail";
        // return "/hello";
    }

    // 管理员通过接口获得所有标注为未审核的房屋信息
    @RequestMapping(path = "getHome")
    @ResponseBody
    public List<?> getHome() {
        return homeService.checkVerifyHome();
    }

    // 管理员通过接口标注某个房屋是否能够通过审核
    @RequestMapping(path = "Verify")
    public void passVerify(@RequestParam String homeName, @RequestParam String verifyCode) {
        homeService.verifyHome(verifyCode, homeName);
    }

    // 管理员通过自己的用户名更改自己的密码
    @RequestMapping(path = "changePwd")
    public void changePwd(@RequestParam String username, @RequestParam String password) {
        adminService.changeAdminPassword(username, password);
    }

}
